<template>
    <el-dropdown  :size="size" :type="type" :plain="plain" :round="round" :circle="circle" :loading="loading" :disabled="disabled" :class="{'btn-disabled':disabled}"
    @command="handleCommand">
        <el-button type="primary">
        {{btnTitle}}<i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu slot="dropdown">
                <el-dropdown-item v-for="(item,index) in hideButton" :key="index" 
                :command="index" 
                :type="item.btnStyle || 'primary'" :disabled="item.disabled">
                <span v-html="item.btnTitle"></span></el-dropdown-item>
              </el-dropdown-menu>
    </el-dropdown>
  </template>
  
  <script>
  // import { clickEvent } from "../event/eventClick";
  export default {
    name: "HCButton",
    data()
    {
      return {};
    },
    props: {
      btnTitle: {
        type: String,
        default: "更多菜单"
      },
      btnObj: {
        type: Object,
        default: () =>
        {
          return {};
        },
      },
      otherObj: {
        type: [Object, Function],
      },
      record: {
        type: [Array, Object, Function],
      },
      size: {
        type: String,
      },
      type: {
        type: String,
        default: "primary",
      },
      plain: {
        type: Boolean,
        default: false,
      },
      round: {
        type: Boolean,
        default: false,
      },
      circle: {
        type: Boolean,
        default: false,
      },
      loading: {
        type: Boolean,
        default: false,
      },
      disabled: {
        type: Boolean,
        default: false,
      },
      autofocus: {
        type: Boolean,
        default: false,
      },
      hideButton:{
        type: Array,
        default: () =>
        {
          return [];
        },
      }
    },
    // 跨层级调用父组件方法  2024-7-4 inject: ['fsback'] 写发没有值时 会报错 Injection "fsback" not found
    inject: {
      fsback: { value: "fsback", default: null },
    },
    methods: {
      clickEvent,
      handleCommand(command){
        this.handleClickEvent(this.hideButton[command], this.record, this.otherObj)
      },
      //按钮点击
      handleClickEvent(P_BtnObj, P_Record, P_otherObj)
      {
        console.log(P_BtnObj, P_Record, P_otherObj)
        if (P_BtnObj.checkedNumberBeforeClick)
        {
          if (P_Record.constructor === Array)
          {
            if (P_Record.length < P_BtnObj.checkedNumberBeforeClick)
            {
  
              this.$message.warning("请至少勾选" + P_BtnObj.checkedNumberBeforeClick + "项");
              return
            }
          }
        }
        if (window.HC_config.VUE_APP_FSANDFORM && P_BtnObj.btnName == 'back')
        {
          if (P_BtnObj.btnEvent.eventType == 'LINK_EVENT' || P_BtnObj.btnEvent.eventType == 'EXECUTE_EVENT')
          {
            this.fsback()
          }
        }
        else
        {
          clickEvent(P_BtnObj.btnEvent, P_Record, P_otherObj);
        }
      }
    },
  };
  </script>
  
  <style lang="scss" scoped>
  .el-button {
    margin-left: 10px;
    padding: 10px 12px;
    &:first-child {
      margin-left: 0px;
    }
  }
  .icon_text {
    margin-left: 10px;
  }
  
  .btn-disabled {
    background-color: #c0c4cc!important;
    cursor: default!important;
    border-color:#c0c4cc!important;
  }
  </style>
  
  